<template>
	<view v-if="pageShow">
		<view class="block">
			<view class="xiaobai ershiba">剩余佣金</view>
			<view class="xiaobai fonweight margin_top2" style="font-size: 60rpx;">{{userInfo.money}}
				<text class="xiaobai titletext">元</text>
			</view>
		</view>
		<view class="mainpadding ffffff block2">
			<view class="flexbetween">
				<view class="titletext fonweight zhonghei">提现方式</view>
				<view class="">
					<u-radio-group v-model="type" placement="row" circle>
						<u-radio activeColor="#c1282e" :customStyle="{marginRight: '15rpx'}" label="微信" :name="1"></u-radio>
						<u-radio activeColor="#c1282e" label="支付宝" :name="2"></u-radio>
					</u-radio-group>
				</view>
			</view>
			
			<view class="paddinglr margin_top flexbetween" v-show="type==1">
				<view class="name white_nowrap">真实姓名</view>
				<input class="color_ling text_a textright" type="text" placeholder="请输入真实姓名" v-model="real_name">
			</view>
			<view class="paddinglr margin_top flexbetween" v-show="type==1">
				<view class="name white_nowrap">授权收款微信</view>
				<view class="name white_nowrap" @click="getopenid" v-if="!openid">点击授权</view>
				<view class="name white_nowrap" @click="getopenid" v-else="openid">已授权</view>
			</view>
			<view class="titletext margin_top fonweight zhonghei">提现金额</view>
			<view class="input margin_top">
				<input class=" " placeholder="请输入提现金额" type="number" v-model="pay_price" />
			</view>
		</view>
		<view class="gudingdb mainpadding flexbetween">
			<view class="submitbtn" @click="chongzhi()">立即提现</view>
		</view>
		<view class="xiaohong main_size flexcenter" @click="goWithdrawalRecord">提现记录</view>
	</view> 
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				userInfo: {},
				pageShow: false,
				pay_price: "",
				type:1, 
				openid:'',
				real_name:'',
				submit_bool:true
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			getopenid(){
				let that = this
				uni.login({
					provider: 'weixin',
					onlyAuthorize: true,
					success: function(resp) {
						console.log("767877",resp);
						that.openid = resp.code
					},
					fail: function(err) {
						console.error("？？？？？？？？？",err);
					}
				});
			},
			init() {
				httpRequest.request('/api/user/getUerInfo', 'GET', {}).then(res => {
					this.userInfo = res.data
					this.pageShow = true
				})
			},
			// 跳转充值记录
			tzczj() {
				uni.navigateTo({
					url: '/pages/tab4/chongzhijl'
				})
			},
			
			goWithdrawalRecord() { //提现记录
				uni.navigateTo({
					url: "/pages/tab4/withdrawalRecord/withdrawalRecord"
				})
			},
			chongzhi() {
				let _this=this;
				if(!this.submit_bool){
					return false;
				}
				if (this.pay_price == "") {
					httpRequest.toast("请输入提现金额")
					return false
				}
				
				if (this.type==1&& !this.real_name) {
					httpRequest.toast("真实姓名不能为空!");
					return false
				}
				this.submit_bool=false;
				httpRequest.request('/api/user/addWithdrawal', 'GET', {
					price: this.pay_price,
					type:this.type,
					openid:this.openid,
					real_name:this.real_name,
				}).then(res => {
					_this.submit_bool=true;
					httpRequest.toast(res.msg)
					if(res.code==-1){
						setTimeout(() => {
							uni.navigateTo({
								url:"/pages/tab4/zhifubxx"
							})
						}, 1000)
					}
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.ljcz {
		width: 328rpx;
		height: 76rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 800;
		background-color: #c1282e;
		border: 2rpx solid #c1282e;
		border-radius: 6rpx;
		color: #FFFFFF;
	}
	
	.jilu {
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FD463E;
		text-align: center;
	}

	.czbtn {
		width: 328rpx;
		height: 76rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 800;
		background-color: #fff;
		border: 2rpx solid #c1282e;
		border-radius: 6rpx;
		color: #c1282e;
	}

	.input {
		background: #F6F6F6;
		border-radius: 6rpx 6rpx 6rpx 6rpx;
		padding: 30rpx;
	}

	.block2 {
		border-radius: 16rpx 16rpx 0 0;
		position: relative;
		top: -20rpx;
	}

	.block {
		padding: 40rpx 30rpx 40rpx;
		background-color: #c1282e;
	}
</style>